/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.coffee.monitor.service.device;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.utils.Clock;

import com.coffee.monitor.entity.Device;
import com.coffee.monitor.entity.DeviceGroup;
import com.coffee.monitor.entity.Sensor;
import com.coffee.monitor.repository.DeviceDao;
import com.coffee.monitor.repository.SensorDao;

/**
 * 设备管理类.
 * 
 * @author coffee
 */
// Spring Service Bean的标识.
@Component
@Transactional
public class SensorService {


	private static Logger logger = LoggerFactory.getLogger(SensorService.class);
	@Autowired
	private SensorDao sensorDao;
	
	private Clock clock = Clock.DEFAULT;

	
	public void save(Sensor sensor){
		sensorDao.save(sensor);
	}
	public Sensor find(Long id){
		return sensorDao.findOne(id);
	}
	public List<Sensor> findByUserId(Long userId){
		return sensorDao.findByUserId(userId);
	}
	public List<Sensor> findByDevice(Long deviceId){
		return sensorDao.findByDevice(new Device(deviceId));
	}
	public List<Sensor> findByDeviceAndUserId(Long deviceId,Long uid){
		return sensorDao.findByDeviceAndUserId(new Device(deviceId),uid);
	}
	
	public void setClock(Clock clock) {
		this.clock = clock;
	}
}
